﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.IO;

namespace Komunikator.Core
{
    public class ConfigFileWriter
    {

        XmlWriter xmlWriter;

        public void CreateNewConfigFile(int ggNumber, string pass)
        {
            FileStream str = new FileStream(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)+"\\cfg.xml", FileMode.Create);
            xmlWriter = XmlWriter.Create(str);

            xmlWriter.WriteStartDocument();
            xmlWriter.WriteStartElement("config");
            xmlWriter.WriteElementString("numergg", ggNumber.ToString());
            xmlWriter.WriteElementString("pass", pass);
            xmlWriter.WriteEndElement();
            xmlWriter.Close();
            str.Close();
        }

        public string Base64Encoding(string pass)
        {
            byte[] stringToEncode = ASCIIEncoding.ASCII.GetBytes(pass);
            string encodedPass = Convert.ToBase64String(stringToEncode);

            return encodedPass;

        }

        public string Base64Decoding(string pass)
        {
            byte[] decodedPassBytes = Convert.FromBase64String(pass);
            return ASCIIEncoding.ASCII.GetString(decodedPassBytes);
        }
    }
}
